<?php

/**
 * This is the model class for table "HocSinh".
 *
 * The followings are the available columns in table 'HocSinh':
 * @property string $MaHS
 * @property string $Ho
 * @property string $Ten
 * @property integer $GioiTinh
 * @property string $NgaySinh
 * @property string $NoiSinh
 * @property string $DanToc
 * @property string $DiaChi
 * @property string $ThuongTru
 * @property string $HoTenCha
 * @property string $HoTenMe
 * @property integer $DienThoai
 * @property string $Hinh
 *
 * The followings are the available model relations:
 * @property QuaTrinh[] $quaTrinhs
 */
class HocSinh extends CActiveRecord
{

	/**
	 * Returns the static model of the specified AR class.
	 * @return HocSinh the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'HocSinh';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('MaHS', 'required'),
			array('GioiTinh, DienThoai', 'numerical', 'integerOnly'=>true),
			array('MaHS, NgaySinh', 'length', 'max'=>10),
			array('Ho, Ten, NoiSinh, DanToc', 'length', 'max'=>20),
			array('DiaChi, ThuongTru, HoTenCha, HoTenMe', 'length', 'max'=>50),
                        array('Hinh', 'file', 'types'=>'jpg, gif, png'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('MaHS, Ho, Ten, GioiTinh, NgaySinh, NoiSinh, DanToc, DiaChi, ThuongTru, HoTenCha, HoTenMe, DienThoai, Hinh', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'quaTrinhs' => array(self::HAS_MANY, 'QuaTrinh', 'MaHS'),
                        'maLop0' => array(self::BELONGS_TO, 'Lop', 'MaLop'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'MaHS' => 'Mã HS',
                        'MaLop'=> 'Mã lớp',
			'Ho' => 'Họ',
			'Ten' => 'Tên',
			'GioiTinh' => 'Giới tính',
			'NgaySinh' => 'Ngày sinh',
			'NoiSinh' => 'Nơi sinh',
			'DanToc' => 'Dân tộc',
			'DiaChi' => 'Địa chỉ',
			'ThuongTru' => 'Thường trú',
			'HoTenCha' => 'Họ tên cha',
			'HoTenMe' => 'Họ tên mẹ',
			'DienThoai' => 'Điện thoại',
			'Hinh' => 'Hình',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('MaHS',$this->MaHS,true);
                $criteria->compare('MaLop',$this->MaLop,true);
		$criteria->compare('Ho',$this->Ho,true);
		$criteria->compare('Ten',$this->Ten,true);
		$criteria->compare('GioiTinh',$this->GioiTinh);
		$criteria->compare('NgaySinh',$this->NgaySinh,true);
		$criteria->compare('NoiSinh',$this->NoiSinh,true);
		$criteria->compare('DanToc',$this->DanToc,true);
		$criteria->compare('DiaChi',$this->DiaChi,true);
		$criteria->compare('ThuongTru',$this->ThuongTru,true);
		$criteria->compare('HoTenCha',$this->HoTenCha,true);
		$criteria->compare('HoTenMe',$this->HoTenMe,true);
		$criteria->compare('DienThoai',$this->DienThoai);
		$criteria->compare('Hinh',$this->Hinh,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
        
        public function getGioiTinh()
        {
            if ($this->GioiTinh==0) return "Nữ"; else return "Nam";
        }
}